<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>

<c:set var="ctx" value="${pageContext.request.contextPath}" />

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>数据源管理</title>


		<script type="text/javascript">
	$(function() {
		$("#startDatepicker").datepicker({
			format : 'yyyy-mm-dd'
		});
		$("#endDatepicker").datepicker({
			format : 'yyyy-mm-dd'
		});
	});

	function deleteOrdeno(item) {	
		$.ajax({
			type : 'post',
			url : '${ctx}/ediOrderSource/deleteOrdeno',
			data : 'id=' + item,
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {
					$("#ordeno_" + item).hide();
					var ordenoNumber = $("#ordenoNumber").html();
					ordenoNumber = Number(ordenoNumber);
					$("#ordenoNumber").html(ordenoNumber - 1);
				}
				alert_message("",data.content,"success",6000);
			},

			error : function() {
				alert_message("操作失败！","网络连接错误，请重新尝试！","error",10000);
			}
		});
	}
	
	function regainOrdeno(item) {
		$.ajax({
			type : 'post',
			url : '${ctx}/ediOrderSource/regainOrdeno',
			data : 'id=' + item,
			dataType : 'json',
			success : function(data) {
				alert_message("",data.content,"success",10000);
			},

			error : function() {
				alert_message("操作失败！","网络连接错误，请重新尝试！","error",10000);
			}
		});
	}
	
	function ajaxfindShopSource(item,type) {
		var value=(type==1? item:item.value);
		$.ajax({
					type : 'post',
					url : '${ctx}/v2/customers/ajaxfindShopSource',
					data : 'ordenoSourceCode=' + value+'&customerCode='+customerCode,
					dataType : 'json',
					success : function(data) {
					    var tempString="<option value=\"\">请选择";
						if (data.status == "1") {
							$.each(data.content,function(i){
							    tempString+="<option value="+data.content[i].shopCode+">"+data.content[i].shopName;
							});
						} 
                        $("#shopCodeId").html(tempString);
                        $("#shopCodeId").trigger("chosen:updated");
					},
					error : function() {
						alert_message("失败！","网络连接错误，请重新尝试！","error",10000);
					}
				});
	}
	
	function ajaxfindOrdenoSource(item) {
		customerCode=item.value;
		$.ajax({
					type : 'post',
					url : '${ctx}/v2/customers/ajaxfindOrdenoSource',
					data : 'customerCode=' + customerCode,
					dataType : 'json',
					success : function(data) {
					    var tempString="";
						if (data.status == "1") {
							$.each(data.content,function(i){
							    tempString+="<option value="+data.content[i].ordenoSourceCode+">"+data.content[i].ordenoSourceName;
							});
						} else {
							alert(data.content);
						}
                        $("#ordenoSourceCode").html(tempString);
                        $("#ordenoSourceCode").trigger("chosen:updated");
                        var ordenoSourceCode=$("#ordenoSourceCode").val();
                        ajaxfindShopSource(ordenoSourceCode,1);
					},
					error : function() {
						alert_message("失败！","网络连接错误，请重新尝试！","error",10000);
					}
				});
	}
</script>
	</head>

	<body>
<section class="content">
		<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
			<form action="${ctx}/ediOrderSource/v2_show" method="post" id="form_solr" class="form-search">
			
				<div class="form-group row">	
				<div class="col-sm-3">
				<div class="input-group col-sm-12"> 	 
				<label class="input-group-text">商家:</label>
				<select name="search_LIKE_customerCode" class="form-control" onchange="ajaxfindOrdenoSource(this)" id="customerId">
							<c:forEach items="${customers}" var="obj">
								<option value="${obj.customerCode}"
									<c:if test="${param.search_LIKE_customerCode eq obj.customerCode}">selected</c:if>> ${obj.customerName}
								</option>
							</c:forEach>
						</select>
				</div>
				</div>
				
				<div class="col-sm-3">
				<div class="input-group col-sm-12"> 
				<label class="input-group-text">平台:</label>
				<select name="search_LIKE_erpType" class="form-control" id="ordenoSourceCode" onchange="ajaxfindShopSource(this,2)">
							<c:forEach items="${ordenoSources}" var="obj">
								<option value="${obj.ordenoSourceCode}"
									<c:if test="${param.search_LIKE_erpType eq obj.ordenoSourceCode}">selected</c:if>>
									${obj.ordenoSourceName}
								</option>
							</c:forEach>
						</select>
				</div>
				</div>
				<div class="col-sm-3">
				<div class="input-group col-sm-12"> 
				<label class="input-group-text">店铺:</label>
				<select name="search_LIKE_shopCode" class="form-control" id="shopCodeId">
						    <option value=""> 请选择 </option>
							<c:forEach items="${shopSources}" var="obj">
								<option value="${obj.shopCode}"
									<c:if test="${param.search_LIKE_shopCode eq obj.shopCode}">selected</c:if>>
									${obj.shopName}
								</option>
							</c:forEach>
						</select>
				</div>
				</div>
				<div class="col-sm-3">
				<div class="input-group col-sm-12"> 
				<label class="input-group-text">省份:</label>
						<select id="search_LIKE_provna" name="search_LIKE_provna" class="form-control">
							<option value="">
								请选择...
							</option>
							<c:forEach items="${areas}" var="area">
								<option value="${area.areaName}"
									<c:if test="${param.search_LIKE_provna eq  area.areaName}">selected</c:if>>
									${area.areaName}
								</option>
							</c:forEach>
						</select>
				</div>
				</div>
		    </div>
			<div class="form-group row">
				<div class="col-sm-3">
				<div class="input-group col-sm-12"> 
				 <label class="input-group-text">订单号:</label>
						<input type="text" name="search_LIKE_ordeno" class="form-control"
							value="${param.search_LIKE_ordeno}" id="search_LIKE_ordeno">
				</div>
				</div>
				<div class="col-sm-3">
				<div class="input-group col-sm-12"> 
							 <label class="input-group-text">商家订单号:</label>
							 
						<input type="text" name="search_LIKE_customerOrdeno" class="form-control"
							value="${param.search_LIKE_customerOrdeno}" id="search_LIKE_customerOrdeno">
						</div>
							 </div>
						<div class="col-sm-3">
				<div class="input-group col-sm-12"> 	
						 <label class="input-group-text">来源单号:</label>
						<input type="text" name="search_LIKE_fromno" class="form-control"
							value="${param.search_LIKE_fromno}" id="search_LIKE_fromno">
				</div>
				</div>
				<div class="col-sm-3">
				<div class="input-group col-sm-12"> 
			    <button id="submit_ediOrder" class="btn btn-info" type="submit">搜索</button>
			    </div>
			    </div>
			</div>	
			
			</form>
			
</div>
</div>
</div>
</div>
<script type="text/javascript">
	var datatable_content;
	var formParam = $("#form_solr").serializeArray();
	var filterParam = {};
	function onQuery() {
		$("#form_solr").submit();
	}
	
	function filter(item){
		formParam = $("#form_solr").serializeArray();
		filterParam[item.name] = item;
		for(var n in filterParam){
			formParam.push(filterParam[n]);
		}
		query();
	}
	
	/* $(function(){
		initTable();
	}); */
	
	function initTable(){
		datatable_content = $("#contentTable").dataTable({
		   "bServerSide":true,
		   "bAutoWidth":false,
           "sAjaxSource":'${ctx}/ediOrderSource/page',
           "fnServerData": callback,
           "bFilter": false,
           "bSort": false,
           "sZeroRecords": "查询无记录！",
           "bProcessing": true,
           "oLanguage": {
               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
            },
             "aoColumns":[
             	 {"mData": "customerCode"},
             	 {"mData": null},
             	 {"mData": "customerOrdeno"},
             	 {"mData": null},
             	 {"mData": "recena"},
             	 {"mData": "provna"},
             	 {"mData": "crtime"},
             	 {"mData": null},
             	 {"mData": null},
             	 {"mData": null},
             ],
             "aoColumnDefs":[
             	{"aTargets": [1],
	              "mRender": function (data, display, row) {
		        	 return "<a href=\"${ctx}/orderMsg/v2_orderMsgDetail/"+row.ordeno+"\">"+row.ordeno+"</a>";
		           }
	            },
             	{"aTargets": [3],
	             "mRender": function (data, display, row) {
	              	var rs = "";
					if(row.forwardSign){
						if( row.forwardSign == 'single'){
							rs = "<span class=\"badge badge-info\">单件</span>";
						}else if(row.forwardSign == 'multiple'){
							rs = "<span class=\"badge badge-warning\">多件</span>";
						}else if(row.forwardSign == 'forward'){
							rs = "<span class=\"badge badge-inverse\">中转发</span>";
						}
					}else if(row.orderType){
						if(row.orderType == 'single'){
							rs = "<span class=\"badge badge-info\">单件</span>";
						}else if(row.orderType == 'multiple'){
							rs ="<span class=\"badge badge-warning\">多件</span>";
						}
					}
					return rs;
		           }
	            },
             	{"aTargets": [6],
	              "mRender": function (data, display, row) {
		        	 return new Date(data.time).Format("yyyy-MM-dd hh:mm:ss");
		           }
	            },
             	{"aTargets": [7],
	              "mRender": function (data, display, row) {
		        	 return row.orderStatus == "cancel" ? "<span class=\"badge badge-warning\">取消单</span>" : 
		        	        row.orderStatus == "ok" ? "<span class=\"badge\">正常单</span>" :
		        	        row.orderStatus == "no" ? "<span class=\"badge badge-inverse\">不处理</span>" : "";
		           }
	            },
             	{"aTargets": [8],
	              "mRender": function (data, display, row) {
		        	 return row.status == "pending" ? "<span class=\"badge badge-important\">等待分拣</span>" : 
		        	        row.status == "finish" ? "<span class=\"badge badge-success\">已处理</span>" : "";
		           }
	            },
             	{"aTargets": [9],
	              "mRender": function (data, display, row) {
		        	 return "<a href=\"#ordersDetailed\" onclick=\"getAjaxOrders("+row.id+")\" role=\button\" class=\"btn btn-small btn-primary\" data-toggle=\"modal\"> 订单详情 </a>"+ 
		        	        "<a href=\"#itemsDetailed\" onclick=\"getAjaxItems("+row.id+")\" role=\"button\" class=\"btn btn-small btn-primary\" data-toggle=\"modal\"> 商品详情 </a>";
		           }
	            },
             ]
		});
	}
	
	function callback(sSource, aoData, fnCallback ) {
	   $.ajax({ 
	       "type": "post",
	       "contentType": "application/json", 
	       "url": sSource,    
	       "dataType": "json",   
	       "data": JSON.stringify(aoData.concat(formParam)),
	       "success": fnCallback  
	   });    
	}
	
	function query(){
		datatable_content.fnDestroy();
		initTable();
	}
</script>
<!--消息提醒-->  	

			<div id="message" class="alert alert-block hide fade in">
				<button type="button" class="close" data-dismiss="alert">&times;</button>
			   <h5 id="message-title">Warning</h5>
			   <span id="message-text"></span>
			</div>
		
		<table id="contentTable"
			class="table table-striped table-bordered table-condensed table-hover ">

			<thead>
				<tr>
				   <th>

						商家
					</th>
					<th>

						订单号
					</th>
					<th>

						来源号
					</th>
					<th>
					<div class="nav dropdown pull-left">
							<a class="dropdown-toggle" data-toggle="dropdown" href="#">
								类型 <b class="caret"></b> </a>
							<ul class="dropdown-menu">
								<li>
									<a href="javascript:filter({name:'search_EQ_orderType',value:'single'})">单件</a>
								</li>
								<li>
									<a href="javascript:filter({name:'search_EQ_orderType',value:'multiple'})">多件</a>
								</li>
							
							</ul>
						</div>
						
					</th>
					<th>

						收货人
					</th>
					<th>

						目的地
					</th>
					<th>


						审核时间
					</th>
					<th>

<div class="nav dropdown pull-left">
							<a class="dropdown-toggle" data-toggle="dropdown" href="#">
								订单状态 <b class="caret"></b> </a>
							<ul class="dropdown-menu">
								<li>
									<a href="javascript:filter({name:'search_EQ_orderStatus',value:'cancel'})">取消单</a>
								</li>
								<li>
									<a href="javascript:filter({name:'search_EQ_orderStatus',value:'ok'})">正常单</a>
								</li>
							    <li>
							    	<a href="javascript:filter({name:'search_EQ_orderStatus',value:'no'})">不处理单</a>
								</li>
								<li>
								    <a href="javascript:filter({name:'search_EQ_orderStatus',value:'finish'})">已分拣单</a>
								</li>
								 <li>
								 	<a href="javascript:filter({name:'search_EQ_orderStatus',value:'pending'})">待分拣单</a>
								</li>
							</ul>
						</div>
					</th>
					<th>


						状态
					</th>
					<th>
						信息
					</th>
				</tr>
			</thead>
			<tbody>
				<c:forEach items="${ediOrders.content}" var="obj">
					<tr id="ordeno_${obj.id }" >
					<td>
							${obj.customerCode}
						</td>
						<td>
						  <a href="${ctx}/orderMsg/v2_orderMsgDetail/${obj.ordeno}">
							${obj.ordeno}</a>
						</td>
						<td>
							${obj.customerOrdeno}
						</td>
						<td>
							<c:choose>
								<c:when test="${not empty obj.forwardSign}">
									<c:if test="${obj.forwardSign eq 'single' }">
										<span class="badge badge-info">单件</span>
									</c:if>
									<c:if test="${obj.forwardSign eq 'multiple' }">
										<span class="badge badge-warning">多件</span>
									</c:if>
									<c:if test="${obj.forwardSign eq 'forward' }">
										<span class="badge badge-inverse">中转发</span>
									</c:if>
								</c:when>
								<c:otherwise>
									<c:if test="${obj.orderType eq 'single' }">
										<span class="badge badge-info">单件</span>
									</c:if>
									<c:if test="${obj.orderType eq 'multiple' }">
										<span class="badge badge-warning">多件</span>
									</c:if>
								</c:otherwise>
							</c:choose>


						</td>
						<td>
							${obj.recena}
						</td>
						<td>
							${obj.provna}
						</td>
						<td>
							${obj.crtime}
						</td>
						<td>
						  <c:if test="${obj.orderStatus eq 'cancel' }">
						      <span class="badge badge-warning">    取消单</span>
						  </c:if>
						  <c:if test="${obj.orderStatus eq 'ok' }">
						      <span class="badge">    正常单</span>
						  </c:if>
						  <c:if test="${obj.orderStatus eq 'no' }">
						      <span class="badge badge-inverse">    不处理</span>
						  </c:if>
						</td>
						<td>
						  <c:if test="${obj.status eq 'pending' }">
						      <span class="badge badge-important">   等待分拣</span>
						  </c:if>
						  <c:if test="${obj.status eq 'finish' }">
						      <span class="badge badge-success">    已处理</span>
						  </c:if>
						</td>
						<td><!--
						 <c:if test="${obj.orderStatus eq 'cancel' }">
						 <a href="#delete_${obj.ordeno}" role="button" class="btn btn-danger" data-toggle="modal">重新发货</a>
						 	<div id="delete_${obj.ordeno}" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
						<div class="modal-body">
							<h4>确定订单<font color="red">${obj.ordeno}</font>重新发货吗？</h4>
						</div>
						<div class="modal-footer">
							<button class="btn" data-dismiss="modal" aria-hidden="true">返回</button>
							 <a class="btn btn-danger" href="javascript: regainOrdeno('${obj.id }');">重新发货</a>
						</div>
					</div>
						     
						  </c:if>
							--><a href="#ordersDetailed" onclick="getAjaxOrders('${obj.id}')"
								role="button" class="btn btn-small btn-info" data-toggle="modal"> 订单详情 </a>

							<a href="#itemsDetailed" onclick="getAjaxItems('${obj.id}')"
								role="button" class="btn btn-small btn-info" data-toggle="modal"> 商品详情 </a>
						</td>
					</tr>
				</c:forEach>
			</tbody>
		</table>

		<div class="modal fade"
			tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
			aria-hidden="true" id="ordersDetailed">
			<div class="modal-dialog" >
			<div class="modal-content" >
			<div class="modal-header">
				<h3 id="myModalLabel">
					订单详细信息
				</h3>
			</div>
			<div class="modal-body" style="width: 1000;height:400px; overflow: auto;">
				<table class="table table-striped table-bordered table-condensed"
					id="modalBodyOrders"></table>
			</div>
			<div class="modal-footer">
				<button class="btn" data-dismiss="modal" aria-hidden="true">
					关闭
				</button>
			</div>
		</div>
		</div>
		</div>
		
		<div style="width: 1000" class="modal fade"
			tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
			aria-hidden="true" id="itemsDetailed">
			<div class="modal-dialog" style="width: 1000">
			<div class="modal-content">
			<div class="modal-header">
				<h3 id="myModalLabel">
					商品详细信息
				</h3>
			</div>
			<div class="modal-body">
				<table class="table table-striped table-bordered table-condensed"
					id="modalBodyItems"></table>
			</div>
			<div class="modal-footer">
				<button class="btn" data-dismiss="modal" aria-hidden="true">
					关闭
				</button>
			</div>
		</div>
		</div>
		</div>

</section>
	</body>
</html>


